import request from '@/utils/request';
import type { Token } from '../entity';
import type {R} from '@/modules/common/entity';
import type { CurrentUser } from '@/modules/security/entity';

const API_URL = '/auth';

export class SecurityApi {
  // 用户登录
  async login(username: string, password: string): Promise<R<Token>> {
    return request({
      url: API_URL + "/login",
      method: 'post',
      data: {
        username,
        password
      }
    })
  }

  // 用户注销
  async logout(): Promise<void> {
    return request({
      url: API_URL + "/logout",
      method: 'post'
    })
  }

  // 获取当前用户信息 
  async userInfo(): Promise<R<CurrentUser>> {
    return request({
      url: API_URL + "/userInfo",
      method: 'get'
    })
  }  
}
